<div id="mainPanel">
    <div class="companies index ">
        <section class="search">
            <h2><?php echo __('Listado de Transportes'); ?></h2>
            <?php echo $this->Form->input('Buscar:', array('class' => 'searchCompany', 'id' => 'searchCompany')) ?>
        </section>


        <div id="companies_list">
            <?php echo $this->element('companies/table'); ?>
        </div>
    </div>
</div>


<div class="actions">
    <h3><?php echo __('Menu'); ?></h3>
    <ul>

        <?php if ($this->Session->read('Auth.User.role') === 'admin') : ?>
            <hr class="hr_menu">

            <li><?php echo $this->Html->link(__('Usuarios'), array('controller' => 'users', 'action' => 'index')); ?> </li>
        <?php endif; ?>

        <hr class="hr_menu">

        <li><?php echo $this->Html->link(__('Crear Orden de Ruta'), array('controller' => 'orders', 'action' => 'add')); ?></li>


        <hr class="hr_menu">
        <li><?php echo $this->Html->link(__('Ver Ordenes de Ruta'), array('controller' => 'orders', 'action' => 'index')); ?></li>
        <li><?php echo $this->form->button(__('Ver Empresas'), array('id' => 'clientCompanyButton')); ?> </li>
        <li><?php echo $this->form->button(__('Ver Transportes'), array('id' => 'companyButton')); ?> </li>
        <li><?php // echo $this->form->button(__('Ver Choferes'), array('id' => 'driverButton'));  ?> </li>
        <li><?php echo $this->Html->link(__('Ver Choferes'), array('controller' => 'Drivers', 'action' => 'index')); ?></li>
        <li><?php echo $this->form->button(__('Ver Camiones'), array('id' => 'vehicleButton')); ?> </li>
        <li><?php echo $this->form->button('Ver Acoplados', array('id' => 'coupledButton')) ?> </li>
        <li><?php echo $this->form->button('Ver Productos', array('id' => 'productButton')) ?> </li>

        <hr class="hr_menu">

        <li><?php echo $this->Html->link(__('Crear Empresa'), array('controller' => 'clientCompanies', 'action' => 'add')); ?></li>
        <li><?php echo $this->form->button(__('Crear Transporte'), array('id' => 'addCompany')); ?></li>
        <li><?php echo $this->Html->link(__('Nuevo Chofer'), array('controller' => 'Drivers', 'action' => 'add')); ?></li>
        <li><?php echo $this->form->button(__('Nuevo Camion'), array('id' => 'addVehicle')); ?> </li>
        <li><?php echo $this->form->button(__('Nuevo Acoplado'), array('id' => 'addCoupled')); ?> </li>
        <li><?php echo $this->form->button(__('Nuevo Producto'), array('id' => 'addProduct')); ?> </li>

    </ul>
</div>
<script>
    $(document).ready(function(){
        
        
        //       Ajax Search keys press
        $('#searchCompany').keyup(function() {
            var name = $("#searchCompany").val();
            $("#companies_list").load('<? echo $this->Html->url('search') ?>',{name:name});
        });
        
        //       Ajax Search by buttons -- MUESTRA LISTADOS

        $('#orderButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Orders/indexAjax') ?>');

        });
        $('#clientCompanyButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../ClientCompanies/indexAjax') ?>');

        });
        $('#companyButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('indexAjax') ?>');

        });
        $('#driverButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Drivers/indexAjax') ?>');

        });
        $('#vehicleButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Vehicles/indexAjax') ?>');

        });
        $('#coupledButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Coupleds/indexAjax') ?>');

        });
    
        $('#productButton').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Products/indexAjax') ?>');

        });
        
        
        
        //       Ajax add methods -- PARA AGREGAR REGISTROS
        
        $('#addOrder').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Orders/addAjax') ?>');

        });
        
        $('#addCompany').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Companies/addAjax') ?>');

        });
        
        $('#addDriver').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Drivers/addAjax') ?>');

        });
        
        $('#addVehicle').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Vehicles/addAjax') ?>');

        });
    
        $('#addCoupled').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Coupleds/addAjax') ?>');

        });
    
        $('#addProduct').click(function() {
            $("#mainPanel").load('<? echo $this->Html->url('../Products/addAjax') ?>');

        });
        
        
    });
</script>